﻿<%@ Page Language="C#" MasterPageFile="~/Admin/admin.master" AutoEventWireup="true"
    CodeFile="PoEdit.aspx.cs" Inherits="PoEdit" Title="Po Edit" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
    Po - Add/Edit</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <script src="myscript/PoEdit.js" type="text/javascript"></script>

    <data:MultiFormView ID="FormView1" DataKeyNames="PoId" runat="server" DataSourceID="PoDataSource"
        OnLoad="FormView1_Load" OnItemCommand="FormView1_ItemCommand">
        <EditItemTemplatePaths>
            <data:TemplatePath Path="~/Admin/UserControls/PoFields.ascx" />
        </EditItemTemplatePaths>
        <InsertItemTemplatePaths>
            <data:TemplatePath Path="~/Admin/UserControls/PoFields.ascx" />
        </InsertItemTemplatePaths>
        <EmptyDataTemplate>
            <b>Po not found!</b>
        </EmptyDataTemplate>
        <FooterTemplate>
            <asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                ValidationGroup="Main" CssClass="button" Text="Insert" />
            <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                ValidationGroup="Main" CssClass="button" Text="Update" />
            <asp:Button ID="PreviewButton" runat="server" CausesValidation="False" Visible="False"
                CommandName="Preview" ToolTip="Print Preview" CssClass="button" Text="Preview" />
            <asp:Button ID="CancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                ToolTip="Return To Manage" CssClass="button" Text="Finish" />
        </FooterTemplate>
    </data:MultiFormView>
    <br />
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <data:PoDataSource ID="PoDataSource" runat="server" SelectMethod="GetByPoId">
        <Parameters>
            <asp:QueryStringParameter Name="PoId" QueryStringField="PoId" Type="String" />
        </Parameters>
    </data:PoDataSource>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" />
        </Triggers>
        <ContentTemplate>
            <asp:Panel runat="server" ID="pn_PODetailsAdd" Width="100%" Visible="false" DefaultButton="btnSave"
                DefaultFocus="dataDrugId">
                <table>
                    <tr>
                        <td colspan="7">
                            <h3>
                                Add Details
                            </h3>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Drug Id:
                        </td>
                        <td>
                            Code
                        </td>
                        <td align="left">
                            Unit
                        </td>
                        <td align="left">
                            Cost Price
                        </td>
                        <td>
                            Quantity:
                        </td>
                        <td>
                            Remark:
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:DropDownList runat="server" ID="dataDrugId" DataSourceID="DrugIdDrugDispoDataSource"
                                DataTextField="DrugName" DataValueField="DrugId" ValidationGroup="Detail" TabIndex="10"
                                onchange="GetDrug($(this).val());" Width="400px" />
                            <%--<data:EntityDropDownList runat="server" ID="dataDrugId" DataSourceID="DrugIdDrugDispoDataSource"
                                DataTextField="DrugName" DataValueField="DrugId" AppendNullItem="true" Required="true"
                                ValidationGroup="Detail" TabIndex="10" NullItemText="< Please Choose ...>" ErrorText="Required"
                                onchange="GetDrug($(this).val());" onkeypress="disableSubmit();" />--%>
                            <data:DrugDispoDataSource ID="DrugIdDrugDispoDataSource" runat="server" SelectMethod="GetPaged"
                                Sort="DrugName ASC" />
                        </td>
                        <td>
                            <span id="CodeResult" style="color: Purple; font-weight: bold"></span>
                        </td>
                        <td>
                            <span id="UnitResult" style="color: #CC6600; font-weight: bold"></span>
                        </td>
                        <td>
                            <span id="CostPriceResult" style="color: #808000; font-weight: bold"></span>
                        </td>
                        <td>
                            <input type="text" runat="server" id="tbQuantity" class="text-input" tabindex="11"
                                value="1" style="width: 30px" />
                        </td>
                        <td>
                            <input type="text" runat="server" id="tbRemark" class="large-input text-input" tabindex="12" />
                        </td>
                        <td>
                            <asp:Button ID="btnSave" Text="Add" class="button" TabIndex="13" runat="server" OnClick="btnSave_Click"
                                ValidationGroup="Detail" />
                            <input type="button" id="btnCancel" value="Cancel" class="button" style="display: none"
                                tabindex="14" />
                        </td>
                    </tr>
                </table>
            </asp:Panel>
            <h3>
                PO Details</h3>
            <data:EntityGridView ID="GridViewPoDetails2" runat="server" AutoGenerateColumns="False"
                AllowSorting="True" OnSelectedIndexChanged="GridViewPoDetails2_SelectedIndexChanged"
                DataSourceID="PoDetailsDataSource2" DataKeyNames="PoDetailId" AllowMultiColumnSorting="false"
                DefaultSortColumnName="PoDetailId" DefaultSortDirection="Descending" ExcelExportFileName="Export_PoDetails.xls"
                Visible='<%# FormView1.DefaultMode != FormViewMode.Insert %>'>
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <a href="#<%#Eval("PoDetailId") %>" onclick="DeleteRow(this,<%#Eval("PoDetailId") %>);"
                                style="display: <%#HasGRN %>">Delete</a>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="DrugId" HeaderText="DrugId" SortExpression="[DrugId]" />
                    <data:HyperLinkField HeaderText="Drug Id" DataNavigateUrlFormatString="DrugDispoEdit.aspx?DrugId={0}"
                        DataNavigateUrlFields="DrugId" DataContainer="DrugIdSource" DataTextField="DrugName" />
                    <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="[Quantity]" />
                    <asp:BoundField DataField="RemainQuantity" HeaderText="Remain Quantity" SortExpression="[RemainQuantity]" />
                    <asp:BoundField DataField="Remark" HeaderText="Remark" SortExpression="[Remark]" />
                </Columns>
                <EmptyDataTemplate>
                    <b>No Po Details Found! </b>
                </EmptyDataTemplate>
            </data:EntityGridView>
            <data:PoDetailsDataSource ID="PoDetailsDataSource2" runat="server" SelectMethod="GetPaged"
                EnableDeepLoad="True" EnableSorting="True">
                <DeepLoadProperties Method="IncludeChildren" Recursive="False">
                    <Types>
                        <data:PoDetailsProperty Name="DrugDispo" />
                        <data:PoDetailsProperty Name="Po" />
                    </Types>
                </DeepLoadProperties>
                <Parameters>
                    <data:SqlParameter Name="WhereClause" UseParameterizedFilters="false">
                        <Filters>
                            <data:PoDetailsFilter Column="PoId" QueryStringField="PoId" ComparisionType="Equals" />
                        </Filters>
                    </data:SqlParameter>
                    <%--<data:SqlParameter Name="Parameters">
                        <Filters>
                            <data:PoDetailsFilter Column="PoId" QueryStringField="PoId" />
                        </Filters>
                    </data:SqlParameter>
                    <data:CustomParameter Name="OrderByClause" Value="" ConvertEmptyStringToNull="false" />--%>
                </Parameters>
            </data:PoDetailsDataSource>
        </ContentTemplate>
    </asp:UpdatePanel>
    <br />
    <h3>
        GRN</h3>
    <data:EntityGridView ID="GridViewGrn1" runat="server" AutoGenerateColumns="False"
        OnSelectedIndexChanged="GridViewGrn1_SelectedIndexChanged" DataSourceID="GrnDataSource1"
        DataKeyNames="GrnId" AllowMultiColumnSorting="false" DefaultSortColumnName=""
        DefaultSortDirection="Ascending" ExcelExportFileName="Export_Grn.xls" Visible='<%# FormView1.DefaultMode != FormViewMode.Insert %>'>
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="GrnId" HeaderText="GRN Id" SortExpression="[GrnId]" />
            <asp:BoundField DataField="GrnDate" HeaderText="Grn Date" SortExpression="[GRNDate]"
                DataFormatString="{0:d}" />
            <data:HyperLinkField HeaderText="Supplier Id" DataNavigateUrlFormatString="SupplierEdit.aspx?SupplierId={0}"
                DataNavigateUrlFields="SupplierId" DataContainer="SupplierIdSource" DataTextField="SupplierName" />
            <asp:BoundField DataField="PreparedBy" HeaderText="Prepared By" SortExpression="[PreparedBy]" />
            <asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="[Amount]"
                DataFormatString="{0:#,##0}">
                <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:BoundField DataField="Remark" HeaderText="Remark" SortExpression="[Remark]" />
            <asp:CheckBoxField DataField="IsComplete" HeaderText="Is Complete" SortExpression="[IsComplete]" />
        </Columns>
        <EmptyDataTemplate>
            <b>No Grn Found! </b>
            <asp:HyperLink runat="server" ID="hypGrn" NavigateUrl="~/admin/GrnEdit.aspx">Add 
            New</asp:HyperLink>
        </EmptyDataTemplate>
    </data:EntityGridView>
    <data:GrnDataSource ID="GrnDataSource1" runat="server" SelectMethod="Find" EnableDeepLoad="True">
        <DeepLoadProperties Method="IncludeChildren" Recursive="False">
            <Types>
                <data:GrnProperty Name="Po" />
                <data:GrnProperty Name="Supplier" />
                <data:GrnProperty Name="WebUser" />
            </Types>
        </DeepLoadProperties>
        <Parameters>
            <data:SqlParameter Name="Parameters">
                <Filters>
                    <data:GrnFilter Column="PoId" QueryStringField="PoId" />
                </Filters>
            </data:SqlParameter>
            <data:CustomParameter Name="OrderBy" Value="" ConvertEmptyStringToNull="false" />
        </Parameters>
    </data:GrnDataSource>
    <br />
</asp:Content>
